<template>
	<view style="background-color: F5F9FF;">
		<headerTop :title="tab_title"></headerTop>
		<scroll-view scroll-y="true">
			<view class="content">
				<!-- 轮播 -->
				<view class="content-top">
					<swiper class="swiper" circular indicator-dots autoplay :interval="5000"
						indicator-active-color="#fff" :duration="500">
						<swiper-item v-for="item in imageList" :key="item.src">
							<image style="width: 100%;height: 100%" :src="item.src" mode=""></image>
						</swiper-item>
					</swiper>
					<!-- <u-swiper indicator keyName="src" :list="imageList" :height="165" :radius="20"
						imgMode="aspectFill"></u-swiper> -->
				</view>
				<!-- <zetank-swiper :height="165" :radius="20" :imageList="imageList" type="default"></zetank-swiper> -->
				<!-- 分类 -->
				<view class="classList">
					<view class="classItem" @click="jump(item)" v-for="(item,index) in classList" :key="index">
						<image :src="$fun.imgUrl(item.image)" mode=""></image>
						<view class="text">
							{{item.name}}
						</view>
					</view>
				</view>
				<!-- 通知 -->
				<view class="inform">
					<view class="inform-info">
						<view class="picture" @click="$fun.jump(`/pageA/noticeList/noticeList?type=0&name=公告`)">
							<image src="/static/newProject/gg_icon.png" mode=""></image>
						</view>
						<view class="info">
							<swiper class="swiper" :circular="true" :vertical="true" :indicator-dots="false"
								:autoplay="true" :interval="3000" :duration="1000">
								<swiper-item v-for="(item,index) in newsList" :key="index">
									<view class="swiper-item"
										@click="$fun.jump(`/pageB/noticeList/noticeList?type=0&name=公告`)">
										<text class="one-omit">{{item.title}}</text>
									</view>
								</swiper-item>
							</swiper>
						</view>
					</view>
				</view>
				<!-- 业务 -->
				<!-- <view class="businessList">
					<view class="businessItem" v-for="(item,index) in product" :key="index">
						<view class="l">
							<image :src="$fun.imgUrl(item.image)" mode=""></image>
							<view class="text_info">
								<view class="title">
									{{item.name}}
								</view>
								<view class="text">
									 {{item.title}}
								</view>
							</view>
						</view>
						<view class="r" @click="jump(`./businessDetails?id=${item.id}`)">
							详情
						</view>
					</view>
				</view> -->
			</view>

			<view class="shopBox">
				<view class="tabLists">
					<image class="img" src="@/static/index/allType.png" mode="heightFix"></image>
				</view>
				<view class="shopList">
					<view class="shopItem" v-for="(item1,index1) in product" :key="index1">
						<view class="shopInfo">
							<image :src="$fun.imgUrl(item1.image)" mode=""></image>
							<view class="info">
								<view class="title">
									{{item1.name}}
								</view>
								<view class="title1">
									{{item1.title}}
								</view>
								<view class="tagBox" v-if="item1.label">
									<view class="tag" v-for="(item2,index2) in  item1.label" :key="index2">
										{{item2}}
									</view>
								</view>
							</view>
						</view>
						<view class="btns">
							<view style="background-color: #FFFFFF;color: #0066FF;border: 1rpx solid #0066FF;"
								class="btn" @click="$fun.jump(`/pageB/businessHtml?id=${item1.id}`)">
								点击查看
							</view>
							<view class="btn" @click="$fun.jump(`/pageB/businessDetails?id=${item1.id}`)">
								立即购买
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>

		<!-- <appUpdate v-if="appUpdateShow" :update_info="update_info" @closeModel="closeModel"></appUpdate> -->
		<!-- #ifdef APP -->
		<!-- <view style="height: 170upx;">

		</view>
		<TabBar :tabBarShow="0"></TabBar> -->
		<!-- #endif -->
		<!-- <u-back-top style="background-color: transparent;bottom:210rpx" :scroll-top="scrollTop" top="80"
			:iconStyle='iconStyle' icon="../../static/Group1335@2x.png"></u-back-top> -->
		<view class="top" @click="iscrollTop" v-show="scrollTop">
			<image src="../../static/Group1335@2x.png" mode=""></image>
		</view>


	</view>
</template>

<script>
	// import appUpdate from "@/components/yzhua006-update/app-update.vue";
	import headerTop from "@/components/dacizi-headtag/dacizi-headtag.vue"
	// import zetankSwiper from "@/component、s/zetank-swiper/components/zetank-swiper/zetank-swiper.vue"
	// import {
	// 	checkUpdate
	// } from "@/components/yzhua006-update/js/app-update-check.js";
	export default {
		components: {
			headerTop,
			// zetankSwiper,
			// appUpdate
		},
		data() {
			return {
				tab_title: "鲸算网云",
				appUpdateShow: false,
				update_info: {},
				imageList: [],
				newsList: [],
				classList: [],
				product: [],
				tabList: [],
				tabIndex: 0,
				scrollTop: false,
				iconStyle: {
					fontSize: '72rpx',
					color: '#2979ff',
					width: '72rpx',
					height: '72rpx'
				},
				qrtext: ''
			};
		},
		onShow() {
			// // #ifdef APP
			// uni.hideTabBar()
			// // #endif
			this.$fun.ajax.post('index/index', {}).then(res => {
				// console.log(res)
				let imgList = res.data.advert
				for (var i = 0; i < imgList.length; i++) {
					imgList[i].src = this.$fun.imgUrl(imgList[i].image)
				}
				// console.log(imgList);
				this.imageList = imgList
				this.classList = res.data.category
				this.newsList = res.data.news
				// this.product = res.data.product
			})
			this.$fun.ajax.post('index/goodstype', {}).then(res => {
				// console.log(res)
				this.tabList = res.data
				this.getShopList(res.data[0].id)
			})
		},
		onLoad() {
			// #ifdef APP-PLUS
			this.getAppInfo(0); //获取线上APP版本信息  参数type 0自动检查  1手动检查（手动检查时，之前取消更新的版本也会提示出来）
			// #endif
			this.$fun.ajax.post('user/gitH5Qrcode', {}).then(res => {
				if (res.code == 1) {
					const pageUrl = res.data.split('#')[1]
					uni.setStorageSync('gitH5Qrcode', JSON.stringify(pageUrl))
					this.qrtext = res.data
				}
			})
		},
		// 分享好友
		onShareAppMessage() {
			return {
				title: '鲸算网云',
				path: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		// 分享朋友圈
		onShareTimeline() {
			return {
				title: '鲸算网云',
				query: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		mounted() {
			uni.onNetworkStatusChange(function(res) {
				console.log(res.isConnected);
				console.log(res.networkType);
			});
		},
		onPageScroll(e) {
			if (e.scrollTop > 0) {
				this.scrollTop = true;
			} else this.scrollTop = false;

		},
		methods: {
			iscrollTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});

			},
			changeTab(index) {
				this.tabIndex = index
				this.getShopList(this.tabList[index].id)
			},
			getShopList(id) {
				this.$fun.ajax.post('index/type_goods', {
					type: id
				}).then(res => {
					// console.log(res)
					for (var i = 0; i < res.data.length; i++) {
						if (res.data[i].label) {
							res.data[i].label = res.data[i].label.split(',')
						} else {
							res.data[i].label = []
						}
					}
					this.product = res.data
				})
			},
			getAppInfo(type) {
				const that = this
				const system_info = uni.getSystemInfoSync();
				let params = {
					os: system_info.platform //本机设备操作系统  （android || ios） 
				}
				if (params.os != 'ios' && params.os != 'android') false; //如果不是安卓或ios 返回false

				//这里自行请求API获取版本信息 建议传入操作系统标识，返回本机对应的操作系统最新版本信息，也就是安卓的返回就是安卓的版本信息  ios返回就是ios的版本信息

				//请求获取最新版本
				plus.runtime.getProperty(plus.runtime.appid, (result) => {
					that.$fun.ajax.post('config/version', {
						version: result.version
					}).then(res => {
						that.update_info = {
							version: res.data.version, //线上版本
							now_url: res.data.pkgUrl, //更新链接
							silent: res.data.silent, //是否是静默更新
							force: res.data.force, //是否是强制更新
							net_check: res.data.net_check, //非WIfi是否提示
							note: res.data.content, //更新内容
						}
						checkUpdate(that.update_info, type, that).then(res => {
							if (res.data) {
								that.appUpdateShow = true
							} else {
								// this.$fun.msg(res.msg)
							}
						}); ///检查更新  
						//checkUpdate 这个方法会做什么？：线上版本号 与 本地版本号做对比 ，如果需要更新  根据静默，强制、wifi等信息执行静默更新或跳转到升级页面
						//跳转升级页面的前提是，需要新建并在pages.json中配置升级页面，配置方法请查看插件详情
					})
				})

			},
			closeModel() {
				this.appUpdateShow = false
			},
			jump(item) {
				console.log(this.qrtext)
				if (item.name == '邀请好友') {
					item.url = item.url + `?qrtext=${this.qrtext}`
					this.$fun.jump(item.url)
				} else {
					this.$fun.jump(item.url)
				}
			}
		}
	}
</script>

<style lang="scss">
	.content {
		// padding: 0 30rpx;
		box-sizing: border-box;
		background-color: #F5F9FF;

		// margin-bottom: 20rpx;
		.content-top {
			// padding: 20rpx;
			margin: 0 0 30rpx;
			// height: 236rpx;
			background: linear-gradient(#0066FF, #fff);

			.swiper {
				width: 690rpx;
				height: 236rpx;
				margin: 0 auto;


			}

		}

		.inform {
			margin: 20rpx 30rpx;

			.inform-info {
				display: flex;
				padding: 0 20rpx;
				height: 50rpx;
				background: #fff;
				border-radius: 10rpx;

				.picture {
					display: flex;
					align-items: center;
					margin-right: 30rpx;

					image {
						width: 28rpx;
						height: 24rpx;
						margin-left: 20rpx;
					}
				}

				.info {
					width: 80%;
					height: 100%;

					.swiper {
						width: 100%;
						height: 100%;

						.swiper-item {
							display: flex;
							align-items: center;
							width: 100%;
							height: 100%;

							text {
								font-size: 24rpx;
								color: #333333;
							}
						}
					}
				}
			}
		}

		.classList {
			margin: 0 30rpx;
			display: flex;
			flex-wrap: wrap;
			background-color: #F5F9FF;

			.classItem {
				width: 20%;
				display: flex;
				margin-bottom: 20rpx;
				flex-direction: column;
				align-items: center;

				image {
					width: 104rpx;
					height: 104rpx;
				}

				.text {
					margin-top: 10rpx;
					color: #333333;
					font-size: 24rpx;
					font-family: Microsoft YaHei
				}
			}
		}

		.businessList {
			margin-top: 40rpx;

			.businessItem {
				margin-bottom: 20rpx;
				height: 170rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(0, 0, 0, 0.1);
				border-radius: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.l {
					margin-left: 30rpx;
					height: 100%;
					display: flex;
					align-items: center;

					image {
						width: 110rpx;
						height: 110rpx;
					}

					.text_info {
						margin-left: 30rpx;
						display: flex;
						flex-direction: column;
						justify-content: center;

						.title {
							font-size: 28rpx;
							font-family: Microsoft YaHei;
							font-weight: bold;
							color: #333333;
						}

						.text {
							margin-top: 8rpx;
							color: #333333;
							font-size: 24rpx;
						}

					}
				}

				.r {
					margin-right: 27rpx;
					width: 150rpx;
					height: 60rpx;
					background: #FFFFFF;
					border: 2rpx solid #0066FF;
					border-radius: 30rpx;
					font-size: 28rpx;
					font-family: Microsoft YaHei;
					color: #0066FF;
					text-align: center;
					line-height: 60rpx;
				}
			}
		}
	}

	.shopBox {
		background-color: #F5F9FF;
		padding: 0 30rpx;

		.tabLists {
			display: flex;
			align-items: center;
			background: #0066ff29;
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			height: 80rpx;
			padding: 0 10rpx;

			.img {
				height: 42rpx;
			}
		}

		.shopList {
			// padding: 32rpx;
			// background: #EEEEEE;

			.shopItem {
				padding: 15rpx;
				background: #FFFFFF;
				border-radius: 15rpx;
				margin-bottom: 24rpx;

				.shopInfo {
					display: flex;
					align-items: center;

					image {
						width: 172rpx;
						height: 172rpx;
					}

					.title {
						margin-top: 45rpx;
						font-size: 30rpx;
						font-family: Source Han Sans CN;
						font-weight: bold;
						color: #333333;
					}

					.title1 {
						margin-top: 10rpx;
						font-size: 26rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #888888;
					}

					.tagBox {
						margin-top: 20rpx;
						display: flex;
						flex-wrap: wrap;

						& .tag:nth-child(2n) {
							color: #2ACB95;
							background-color: rgba(191, 230, 220, 0.5);
						}

						.tag {
							padding: 6rpx 14rpx;
							color: #60b5ff;
							background-color: rgba(215, 238, 255, 0.5);
							border-radius: 4rpx;
							font-size: 20rpx;
							margin-right: 10rpx;

						}
					}
				}

				.btns {
					margin-top: 30rpx;
					display: flex;
					justify-content: space-around;
					padding-bottom: 20rpx;

					.btn {
						background-color: #0066FF;
						color: #fff;
						width: 268rpx;
						height: 64rpx;
						border-radius: 32rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 26rpx;
						font-weight: 600;
					}
				}
			}
		}
	}

	.top {
		position: fixed;
		bottom: 210rpx;
		right: 36rpx;

		image {
			width: 72rpx;
			height: 72rpx;
		}
	}
</style>